package cn.powertime.evaluation.service.impl;

import cn.powertime.evaluation.Constants;
import cn.powertime.evaluation.entity.CpsWrongQuestions;
import cn.powertime.evaluation.mapper.CpsWrongQuestionsMapper;
import cn.powertime.evaluation.service.CpsWrongQuestionsService;
import cn.powertime.evaluation.vo.RespAnswerTopicListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户错题记录表 服务实现类
 * </p>
 *
 * @author liqi
 * @since 2019-09-23
 */
@Service
public class CpsWrongQuestionsServiceImpl extends ServiceImpl<CpsWrongQuestionsMapper, CpsWrongQuestions> implements CpsWrongQuestionsService {

    @Autowired
    private CpsWrongQuestionsMapper wrongQuestionsMapper;

    @Override
    public Boolean checkWrongTopicOnly(Long userId, Long topicId) {
        QueryWrapper<CpsWrongQuestions> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("topic_id", topicId);
        wrapper.eq("status", Constants.STATUS_NORMAL);
        return wrongQuestionsMapper.selectCount(wrapper) > 0;
    }

    @Override
    public Page<RespAnswerTopicListVo> list(Page page, Long userId) {
        return this.wrongQuestionsMapper.selectPage(page, userId);
    }

}
